package org.diysearch.services;

import org.diysearch.helpers.LinkHelper;
import org.diysearch.interfaces.Product;
import org.diysearch.models.Link;
import org.diysearch.models.Status;
import org.diysearch.products.JsonProduct;

public class EditLink extends BaseService {
	private String uri;
	
	@Override
	public Product execute() throws Exception {
		Product p = new JsonProduct();
		Status s = new Status();
		p.setWriter(writer);
		
		int id = Integer.parseInt(request.getParameter("id"));
		
		Link link = LinkHelper.fetchLink(id);
		s.setAttributes(link.toMap());
		s.setCode(1);
		s.setMessage("editing link: " + link.getTitle());
		
		p.setOutput(s);
		
		return p;
	}

	@Override
	public boolean isWriter() {
		return true;
	}

	@Override
	public String getUri() {
		return uri;
	}

	@Override
	public void setUri(String uri) {
		this.uri=uri;
	}

}
